from django.http import HttpResponse
from django.utils.timezone import make_aware
from datetime import datetime


def index(request):
    re = HttpResponse(content="index")
    expires = datetime.now()
    expires = make_aware(expires)
    # expires大于max_age
    re.set_cookie('username', 'dimingda', expires=expires, path='/list/')
    return re


def list(request):
    cookies = request.COOKIES
    print(cookies)
    return HttpResponse("hello")


def session_demo(request):
    # request.session['username'] = "dimingda"
    username = request.session.get("username")
    # 删除
    # username = request.session.pop("username")
    # clear()清除当前用户
    # flush()删除session_id
    # set_expiry()设置-1代表已经过期
    # clear_expired()
    return HttpResponse(username)
